package com.zk.yygh.user.controller.api;

import com.zk.yygh.hosp.result.Result;
import com.zk.yygh.hosp.utils.AuthContextHolder;
import com.zk.yygh.model.user.UserInfo;
import com.zk.yygh.user.service.UserInfoService;
import com.zk.yygh.vo.user.LoginVo;
import com.zk.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author: 张凯
 * @date: 2022/6/12 - 14:40
 */
@Api(value = "用户相关api")
@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户手机登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String, Object> res = userInfoService.login(loginVo);
        return Result.ok(res);
    }

    @ApiOperation(value = "用户认证")
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }

    @ApiOperation(value = "根据用户id获取用户信息")
    @GetMapping("/getUserInfoById")
    public Result getUserInfoById(HttpServletRequest request){
        UserInfo userInfo = userInfoService.getUserInfoById(AuthContextHolder.getUserId(request));
        return Result.ok(userInfo);
    }

}
